package com.baomidou.springwind.test;

import java.util.Random;

/**
 * Created by Administrator on 2016/12/19.
 */
public class Coin extends Tosser {
    private int negative = 0;
    private int positive = 0;

    public Coin(int turn) {
        super(new Seeder(2), turn);
    }

    @Override
    public void showResults() {
        System.out.println("Play turns:" + turn);
        System.out.println("Get negative:" + negative + ","
                + (float) negative / (float) turn * 100 + "%");
        System.out.println("Get positive:" + positive + ","
                + (float) positive / (float) turn * 100 + "%");
    }

    @Override
    public void runToss() {
        for (int i = 0; i < turn; i++) {
            int value = curseed.getValue();
            if (value == 1) {
                negative++;
            } else {
                positive++;
            }
        }
    }

    /**
     * 抽象实现
     */


    /**
     * 单独实现
     */
/*
    private int nInt = 0;
    private int pInt = 0;
    private int turn;

    public Coin(int turn) {
        this.turn = turn;
    }


    public void tossing() {
        Random random = new Random();
        for (int i = 0; i < turn; i++) {
            int num = random.nextInt(2);
            if (num == 1) {
                nInt++;
            } else {
                pInt++;
            }
        }
        System.out.println(nInt);
        System.out.println(pInt);
    }


    }*/
    public static void main(String[] args) {
        Coin coin = new Coin(2000000);
        coin.runToss();
        coin.showResults();

    }
}
